package com.pureut.storage.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.pureut.storage.dto.*;
import com.pureut.storage.export.CheckManagementExport;
import com.pureut.storage.service.CheckManagementService;
import com.pureut.storage.util.ExcelUtil;
import com.pureut.storage.vo.*;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 库存盘点控制层
 *
 * @author: CM
 * @date: 2023/1/13  11:13
 */
@RestController
@RequestMapping("/checkManagement")
public class CheckManagementController extends BaseController {

    @Resource
    private CheckManagementService checkManagementService;

    /**
     * 新增盘点单
     */
    //@SaCheckPermission("warehouse:inside:inventoryCount:add")
    @Log(title = "新增盘点单", businessType = BusinessType.INSERT)
    @PostMapping("/addCheck")
    public R<Void> addCheck(@RequestBody AddCheckVo addCheckVo) throws Exception {
        return toAjax(checkManagementService.addCheck(addCheckVo));
    }

    /**
     * 查看盘点单
     */
    //@SaCheckPermission("warehouse:inside:inventoryCount:query")
    @GetMapping("/view/{id}")
    public R<?> view(@PathVariable("id") Long id) throws Exception {
        return R.ok(checkManagementService.view(id));
    }

    /**
     * 删除单据
     */
    //@SaCheckPermission("warehouse:inside:inventoryCount:remove")
    @Log(title = "删除单据", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{ids}")
    public R<Void> delete(@PathVariable("ids") String ids) throws Exception {
        return toAjax(checkManagementService.delete(ids));
    }

    /**
     * 关结单据
     */
    //@SaCheckPermission("warehouse:inside:inventoryCount:close")
    @Log(title = "关结返工出库单", businessType = BusinessType.UPDATE)
    @PostMapping("/close")
    public R<Void> close(@RequestBody CheckCloseVo checkCloseVo) throws Exception {
        return toAjax(checkManagementService.close(checkCloseVo));
    }

    /**
     * 盘点信息列表查询
     */
    @GetMapping("/list")
    //@SaCheckPermission("warehouse:inside:inventoryCount:list")
    public TableDataInfo<CheckListDto> getList(CheckManagementVo checkManagementVo, PageQuery pageQuery) {
        //查询库存列表
        return checkManagementService.getList(checkManagementVo, pageQuery);
    }

    /**
     * 查看单据明细
     */
    @GetMapping("/detailList")
    public TableDataInfo getListDetail(String docNum, PageQuery pageQuery) {
        //查询库存列表
        return checkManagementService.getListDetail(docNum, pageQuery);

    }

    /**
     * 查看物料明细
     */
    @GetMapping("/materialList")
    public TableDataInfo getmaterialList(String docNum, PageQuery pageQuery) {
        //查询库存列表
        return checkManagementService.getmaterialList(docNum, pageQuery);
    }

    /**
     * 盘点
     */
    //@SaCheckPermission("warehouse:inside:inventoryCount:pandian")
    @Log(title = "盘点", businessType = BusinessType.UPDATE)
    @PostMapping("/pdCheck")
    public R<?> pdCheck(@RequestBody PdVo pdVo) throws Exception {
        return R.ok(checkManagementService.pdCheck(pdVo));
    }

    /**
     * 弹窗提示
     */
    @Log(title = "盘点", businessType = BusinessType.UPDATE)
    @PostMapping("/openWindow")
    public R<?> openWindow(@RequestBody PdVo pdVo) throws Exception {
        return R.ok(checkManagementService.openWindow(pdVo));
    }

    /**
     * 盘点完成
     */
    @Log(title = "盘点完成", businessType = BusinessType.UPDATE)
    @PostMapping("/checkInventory")
    public R<?> checkInventory(@RequestBody PdVo pdVo) throws Exception {
        return R.ok(checkManagementService.checkInventory(pdVo));
    }

    /**
     * 盘点物料下拉
     */
    @GetMapping("/getMaterial")
    public R<?> getMaterial(Long id) throws Exception {
        return R.ok(checkManagementService.getMaterial(id));
    }

    /**
     * 盘点单审核-单据明细
     */
    @GetMapping("/reviceDocDetail/{id}")
    public R<?> reviceDocDetail(@PathVariable("id") Long id) throws Exception {
        return R.ok(checkManagementService.reviceDocDetail(id));

    }

    /**
     * 盘点单审核-物料明细
     */
    @GetMapping("/reviceMaterialDetail/{id}")
    public R<?> reviceMaterialDetail(@PathVariable("id") Long id) throws Exception {
        return R.ok(checkManagementService.reviceMaterialDetail(id));
    }

    /**
     * 盘点审核回显
     */
    @GetMapping("/getRevice/{id}")
    public R<?> getRevice(@PathVariable("id") Long id) throws Exception {
        return R.ok(checkManagementService.getRevice(id));
    }

    /**
     * 审核OK
     */
    @Log(title = "审核Ok", businessType = BusinessType.UPDATE)
    @PutMapping("/reviceOk")
    public R<Void> reviceOk(@RequestBody PdVo pdVo) throws Exception {
        return toAjax(checkManagementService.reviceOk(pdVo));
    }

    /**
     * 审核NG
     */
    @Log(title = "审核NG", businessType = BusinessType.UPDATE)
    @PutMapping("/reviceNg")
    public R<Void> reviceNg(@RequestBody PdVo pdVo) throws Exception {
        return toAjax(checkManagementService.reviceNg(pdVo));
    }

    /**
     * 单据审核确定
     */
    //@SaCheckPermission("warehouse:inside:inventoryCount:examine")
    @Log(title = "审核单据", businessType = BusinessType.UPDATE)
    @PutMapping("/checkReview")
    public R<Void> checkReview(@Validated @RequestBody OrderReviewVo orderReviewVo) throws Exception {
        return toAjax(checkManagementService.checkReview(orderReviewVo));
    }

    /**
     * 盘点物料Pda列表
     */
    @GetMapping("/getCheckListPda")
    public TableDataInfo<CheckListPdaDto> getCheckListPda(PageQuery pageQuery) {
        //查询库存列表
      return checkManagementService.getCheckListPda(pageQuery);
    }

    /**
     * 手持Pda明细盘点列表
     */
    @GetMapping("/getCheckDetailListPda")
    public R getCheckDetailListPda(CheckListDetailPdaVo checkListDetailPdaVo) {
        //查询库存列表
        CheckListDetailPdaInfoDto checkDetailListPda = checkManagementService.getCheckDetailListPda(checkListDetailPdaVo);
        return R.ok(checkDetailListPda);
    }

}
